package com.fallsvc.re.javasesets.jdk17;

/**
 * @auther falls_vc
 * description:
 * @date 2025/10/25  21:10
 */
public class Demo1 {
    public static void main1(String[] args) {
        String data = "one";
        int result = 0; // 接收数据的返回值
        switch (data) {
            case "one":
                result = 1; // 为result重新赋值
                break;
            case "two":
                result = 2; // 为result重新赋值
                break;
            default:
                result = -1; // 为result重新赋值
                break;
        }
        System.out.println(result);
    }

    public static void main(String[] args) {
        String data = "one";
        int result = switch (data) {
            case "one" -> 1;
            case "two" -> 2;
            default -> -1;
        };

        int ret = switch (data) {
            case "one" -> 1;
            case "two" -> 2;
            default -> -1;
        };

        System.out.println(result);
        System.out.println(ret);
    }

    public static void main2(String[] args) {
        String data = "one";
        int result = switch (data) {
            case "one":
                yield 1;
            case "two":
                yield 2;
            default:
                yield -1;
        };
        System.out.println(result);

    }
}